<?php

/**
 * 语言设置
 * Author: Zeon
 * Date: 2017/8/9
 * Created by Panxsoft.
 */
namespace App\Http\Middleware;

use App\Services\Utils\ApiChecker;
use Closure;
use Illuminate\Http\Request;

class LanguageSetting {
    
    use ApiChecker;

    const GLOBAL_LANG_SESSION_KEY = 'GLOBAL_LANG';
    
    public function handle(Request $request, Closure $next)
    {
        if ($request->exists('lang')) {
            session([
                self::GLOBAL_LANG_SESSION_KEY => request()->lang ?: 'zh'
            ]);
        }

        app()->setLocale(session(self::GLOBAL_LANG_SESSION_KEY, 'zh'));

        return $next($request);
    }
}